<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>516影视 - HTML5版</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Microsoft YaHei', sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
            color: #fff;
            min-height: 100vh;
        }
        
        .header {
            background: rgba(0, 0, 0, 0.7);
            padding: 1rem 2rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
            position: sticky;
            top: 0;
            z-index: 100;
            backdrop-filter: blur(10px);
        }
        
        .logo {
            font-size: 2rem;
            font-weight: bold;
            background: linear-gradient(45deg, #ff0080, #00ffcc);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .nav {
            display: flex;
            gap: 2rem;
        }
        
        .nav-item {
            padding: 0.5rem 1.5rem;
            border-radius: 25px;
            cursor: pointer;
            transition: all 0.3s ease;
            background: rgba(255, 255, 255, 0.1);
            border: 1px solid rgba(255, 255, 255, 0.2);
        }
        
        .nav-item:hover, .nav-item.active {
            background: linear-gradient(45deg, #ff0080, #00ffcc);
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(255, 0, 128, 0.4);
        }
        
        .search-bar {
            display: flex;
            gap: 0.5rem;
        }
        
        .search-bar input {
            padding: 0.5rem 1rem;
            border-radius: 20px;
            border: none;
            background: rgba(255, 255, 255, 0.1);
            color: white;
            outline: none;
            width: 250px;
        }
        
        .search-bar button {
            padding: 0.5rem 1rem;
            border-radius: 20px;
            border: none;
            background: linear-gradient(45deg, #ff0080, #00ffcc);
            color: white;
            cursor: pointer;
            transition: all 0.3s ease;
        }
        
        .search-bar button:hover {
            transform: scale(1.05);
            box-shadow: 0 5px 15px rgba(255, 0, 128, 0.4);
        }
        
        .container {
            max-width: 1400px;
            margin: 0 auto;
            padding: 2rem;
        }
        
        .player-container {
            background: rgba(0, 0, 0, 0.5);
            border-radius: 15px;
            padding: 2rem;
            margin-bottom: 2rem;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
            display: none;
        }
        
        .player-container.active {
            display: block;
        }
        
        .video-container {
            position: relative;
            width: 100%;
            padding-bottom: 56.25%; /* 16:9 宽高比 */
            height: 0;
            overflow: hidden;
            border-radius: 10px;
            margin-bottom: 1rem;
            background: #000;
        }
        
        .video-container video {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        
        .video-info {
            padding: 1rem 0;
        }
        
        .video-title {
            font-size: 1.8rem;
            margin-bottom: 0.5rem;
            color: #fff;
        }
        
        .video-meta {
            display: flex;
            gap: 1rem;
            color: #aaa;
            margin-bottom: 1rem;
        }
        
        .video-description {
            color: #ccc;
            line-height: 1.6;
        }
        
        .section {
            margin-bottom: 3rem;
        }
        
        .section-title {
            font-size: 1.8rem;
            margin-bottom: 1.5rem;
            padding-bottom: 0.5rem;
            border-bottom: 2px solid rgba(255, 255, 255, 0.2);
            display: flex;
            align-items: center;
            gap: 1rem;
        }
        
        .section-title::before {
            content: '';
            width: 5px;
            height: 25px;
            background: linear-gradient(45deg, #ff0080, #00ffcc);
            border-radius: 3px;
        }
        
        .video-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
            gap: 1.5rem;
        }
        
        .video-card {
            background: rgba(255, 255, 255, 0.05);
            border-radius: 10px;
            overflow: hidden;
            transition: all 0.3s ease;
            cursor: pointer;
            border: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        .video-card:hover {
            transform: translateY(-10px);
            box-shadow: 0 15px 30px rgba(0, 0, 0, 0.5);
            background: rgba(255, 255, 255, 0.1);
        }
        
        .video-thumbnail {
            width: 100%;
            height: 160px;
            background: linear-gradient(45deg, #333, #555);
            position: relative;
            overflow: hidden;
        }
        
        .video-thumbnail::after {
            content: '▶';
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: rgba(0, 0, 0, 0.7);
            color: white;
            width: 50px;
            height: 50px;
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 1.2rem;
            opacity: 0;
            transition: opacity 0.3s ease;
        }
        
        .video-card:hover .video-thumbnail::after {
            opacity: 1;
        }
        
        .video-card-content {
            padding: 1rem;
        }
        
        .video-card-title {
            font-size: 1.1rem;
            margin-bottom: 0.5rem;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        
        .video-card-meta {
            display: flex;
            justify-content: space-between;
            color: #aaa;
            font-size: 0.9rem;
        }
        
        .footer {
            background: rgba(0, 0, 0, 0.7);
            padding: 2rem;
            text-align: center;
            margin-top: 3rem;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        .footer-content {
            max-width: 1200px;
            margin: 0 auto;
        }
        
        .footer-links {
            display: flex;
            justify-content: center;
            gap: 2rem;
            margin-bottom: 1rem;
            flex-wrap: wrap;
        }
        
        .footer-link {
            color: #aaa;
            text-decoration: none;
            transition: color 0.3s ease;
        }
        
        .footer-link:hover {
            color: #fff;
        }
        
        .copyright {
            color: #777;
            font-size: 0.9rem;
        }
        
        .loading {
            text-align: center;
            padding: 2rem;
            color: #aaa;
        }
        
        .error {
            text-align: center;
            padding: 2rem;
            color: #ff6b6b;
            background: rgba(255, 107, 107, 0.1);
            border-radius: 10px;
            margin: 1rem 0;
        }
        
        @media (max-width: 768px) {
            .header {
                flex-direction: column;
                gap: 1rem;
            }
            
            .nav {
                flex-wrap: wrap;
                justify-content: center;
            }
            
            .search-bar {
                width: 100%;
                justify-content: center;
            }
            
            .search-bar input {
                width: 70%;
            }
            
            .video-grid {
                grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
            }
        }
    </style>
</head>
<body>
    <header class="header">
        <div class="logo">41影视</div>
        <nav class="nav">
            <div class="nav-item active" data-category="all">全部</div>
            <div class="nav-item" data-category="europe">欧美区</div>
            <div class="nav-item" data-category="china">国产区</div>
            <div class="nav-item" data-category="japan">日韩区</div>
        </nav>
        <div class="search-bar">
            <input type="text" placeholder="搜索视频..." id="search-input">
            <button id="search-btn">搜索</button>
        </div>
    </header>
    
    <div class="container">
        <div class="player-container" id="player-container">
            <div class="video-container">
                <video id="mainVideo" controls playsinline>
                    <source id="videoSource" src="" type="video/mp4">
                    您的浏览器不支持 HTML5 视频标签。
                </video>
            </div>
            <div class="video-info">
                <h1 class="video-title" id="video-title">请选择视频</h1>
                <div class="video-meta" id="video-meta">
                    <span>播放量: 0</span>
                    <span>时长: 0:00</span>
                    <span>上传时间: -</span>
                </div>
                <p class="video-description" id="video-description">
                    请在左侧选择您想观看的视频
                </p>
            </div>
        </div>
        
        <section class="section" id="europe-section">
            <h2 class="section-title">欧美区</h2>
            <div class="video-grid" id="europe-videos">
                <div class="loading">加载中...</div>
            </div>
        </section>
        
        <section class="section" id="china-section">
            <h2 class="section-title">国产区</h2>
            <div class="video-grid" id="china-videos">
                <div class="loading">加载中...</div>
            </div>
        </section>
        
        <section class="section" id="japan-section">
            <h2 class="section-title">日韩区</h2>
            <div class="video-grid" id="japan-videos">
                <div class="loading">加载中...</div>
            </div>
        </section>
    </div>
    
    <footer class="footer">
        <div class="footer-content">
            <div class="footer-links">
                <a href="#" class="footer-link">关于我们</a>
                <a href="#" class="footer-link">联系方式</a>
                <a href="#" class="footer-link">用户协议</a>
                <a href="#" class="footer-link">隐私政策</a>
                <a href="#" class="footer-link">帮助中心</a>
            </div>
            <div class="copyright">
                &copy; 2023 41影视 在线视频平台. 保留所有权利.
            </div>
        </div>
    </footer>
    
    <script>
        // 视频分类映射
        const videoCategories = {
            'europe': ['iron_man_1.mp4', 'iron_man_2.mp4', 'iron_man_3.mp4', 'avengers_endgame.mp4', 
                      'game_of_thrones.mp4', 'fast_furious.mp4', 'harry_potter.mp4'],
            'china': ['minjian_baiduren.mp4', 'nezha.mp4', 'wolf_warrior.mp4', 'hello_mom.mp4', 'se_jie.mp4'],
            'japan': ['demon_slayer.mp4', 'parasite.mp4', 'your_name.mp4', 'squid_game.mp4']
        };

        // 视频元数据
        const videoMetadata = {
            'iron_man_1.mp4': {
                title: '《钢铁侠1》完整版',
                views: '420万',
                duration: '02:06:15',
                uploadTime: '2022-01-15',
                description: '托尼·斯塔克是一位身价亿万的企业家，同时还是一位天才发明家。在一次武器测试中，托尼不幸被绑架，被迫制造一种毁灭性武器。为了保护自己的心脏，托尼制造了一套盔甲，并成功逃脱。回到美国后，托尼开始完善盔甲设计，化身钢铁侠，保护世界免受威胁。'
            },
            'iron_man_2.mp4': {
                title: '《钢铁侠2》完整版',
                views: '380万',
                duration: '02:04:45',
                uploadTime: '2022-02-20',
                description: '托尼·斯塔克公开了自己是钢铁侠的身份，引发了全球范围内的巨大反响。与此同时，托尼必须面对来自俄罗斯科学家伊凡·万科的挑战，同时还要应对自己体内钯元素中毒的问题。在神盾局的帮助下，托尼最终找到了新的元素，并成功击败了敌人。'
            },
            'iron_man_3.mp4': {
                title: '《钢铁侠3》完整版',
                views: '395万',
                duration: '02:10:22',
                uploadTime: '2022-03-10',
                description: '在纽约大战之后，托尼·斯塔克患上了焦虑症，夜不能寐。与此同时，一个名为"满大人"的恐怖分子头目在全球范围内发动恐怖袭击。托尼的个人世界被摧毁，他必须依靠自己的才智和本能，在没有战甲的情况下保护那些他最珍视的人。'
            },
            'avengers_endgame.mp4': {
                title: '《复仇者联盟：终局之战》精彩片段',
                views: '245万',
                duration: '02:15',
                uploadTime: '2022-03-15',
                description: '漫威电影宇宙中最震撼的决战场景，钢铁侠的最终牺牲，美国队长的最后一战。'
            },
            'game_of_thrones.mp4': {
                title: '《权力的游戏》经典对决',
                views: '189万',
                duration: '03:42',
                uploadTime: '2022-05-20',
                description: '琼恩·雪诺与夜王的终极对决，维斯特洛大陆的命运之战。'
            },
            'fast_furious.mp4': {
                title: '《速度与激情》特技集锦',
                views: '156万',
                duration: '04:23',
                uploadTime: '2022-07-10',
                description: '飞车家族最惊险刺激的特技场面，超越物理极限的动作设计。'
            },
            'harry_potter.mp4': {
                title: '《哈利波特》魔法世界回顾',
                views: '210万',
                duration: '05:12',
                uploadTime: '2022-09-05',
                description: '霍格沃茨魔法学校的精彩瞬间，从魔法石到死亡圣器的完整旅程。'
            },
            'minjian_baiduren.mp4': {
                title: '《民间摆渡人》纪录片',
                views: '285万',
                duration: '01:28:35',
                uploadTime: '2022-04-12',
                description: '记录中国民间摆渡人的真实生活，展现他们在江河湖海间默默奉献的故事。这些无名英雄用简陋的船只连接两岸，承载着村民的希望与梦想。'
            },
            'nezha.mp4': {
                title: '《哪吒之魔童降世》幕后制作',
                views: '278万',
                duration: '08:12',
                uploadTime: '2022-06-18',
                description: '国产动画电影的新高度，揭秘其独特的艺术风格和制作过程。'
            },
            'wolf_warrior.mp4': {
                title: '《战狼2》动作戏解析',
                views: '195万',
                duration: '05:33',
                uploadTime: '2022-08-22',
                description: '吴京自导自演的军事动作片，分析其真实震撼的动作场面。'
            },
            'hello_mom.mp4': {
                title: '《你好，李焕英》感人片段',
                views: '245万',
                duration: '04:56',
                uploadTime: '2022-10-30',
                description: '贾玲导演的处女作，母女情深的温馨时刻，笑中带泪的感人故事。'
            },
            'se_jie.mp4': {
                title: '《色戒》完整版',
                views: '568万',
                duration: '02:38:16',
                uploadTime: '2023-01-15',
                description: '李安导演的经典作品，改编自张爱玲同名短篇小说。讲述抗战时期，女大学生王佳芝利用美色接近汉奸易先生意图行刺的故事。影片深刻探讨了爱情、忠诚与背叛的复杂关系。'
            },
            'demon_slayer.mp4': {
                title: '《鬼灭之刃》无限列车篇精彩战斗',
                views: '312万',
                duration: '07:22',
                uploadTime: '2022-05-05',
                description: '灶门炭治郎与炎柱炼狱杏寿郎对抗下弦之壹的震撼战斗场面。'
            },
            'parasite.mp4': {
                title: '《寄生虫》奥斯卡获奖片段',
                views: '267万',
                duration: '05:45',
                uploadTime: '2022-07-25',
                description: '韩国电影史上首部获得奥斯卡最佳影片的作品，阶级冲突的深刻描绘。'
            },
            'your_name.mp4': {
                title: '《你的名字》经典场景回顾',
                views: '298万',
                duration: '06:18',
                uploadTime: '2022-09-15',
                description: '新海诚导演的动画电影，彗星降临的末世之美与跨越时空的相遇。'
            },
            'squid_game.mp4': {
                title: '《鱿鱼游戏》经典游戏解析',
                views: '354万',
                duration: '09:05',
                uploadTime: '2022-11-08',
                description: 'Netflix热门韩剧，解析一二三木头人、抠糖饼等致命游戏的规则与策略。'
            }
        };
        
        // DOM元素
        const playerContainer = document.getElementById('player-container');
        const videoElement = document.getElementById('mainVideo');
        const videoSource = document.getElementById('videoSource');
        const videoTitle = document.getElementById('video-title');
        const videoMeta = document.getElementById('video-meta');
        const videoDescription = document.getElementById('video-description');
        const navItems = document.querySelectorAll('.nav-item');
        const searchInput = document.getElementById('search-input');
        const searchBtn = document.getElementById('search-btn');
        const sections = {
            europe: document.getElementById('europe-section'),
            china: document.getElementById('china-section'),
            japan: document.getElementById('japan-section')
        };
        const videoGrids = {
            europe: document.getElementById('europe-videos'),
            china: document.getElementById('china-videos'),
            japan: document.getElementById('japan-videos')
        };
        
        // 从服务器获取视频列表
        async function loadVideoList() {
            try {
                const response = await fetch('/list');
                if (!response.ok) {
                    throw new Error('无法获取视频列表');
                }
                const videos = await response.json();
                
                // 清空所有视频网格
                Object.values(videoGrids).forEach(grid => {
                    grid.innerHTML = '';
                });
                
                // 根据分类填充视频
                videos.forEach(videoFile => {
                    const metadata = videoMetadata[videoFile] || {
                        title: videoFile,
                        views: '0',
                        duration: '未知',
                        uploadTime: '未知',
                        description: '暂无描述'
                    };
                    
                    // 确定视频分类
                    let category = 'other';
                    for (const [cat, files] of Object.entries(videoCategories)) {
                        if (files.includes(videoFile)) {
                            category = cat;
                            break;
                        }
                    }
                    
                    // 创建视频卡片
                    const videoCard = createVideoCard(videoFile, metadata);
                    
                    // 添加到对应的网格
                    if (videoGrids[category]) {
                        videoGrids[category].appendChild(videoCard);
                    }
                });
                
                // 检查是否有空分类
                Object.entries(videoGrids).forEach(([category, grid]) => {
                    if (grid.children.length === 0) {
                        grid.innerHTML = '<div class="error">暂无视频</div>';
                    }
                });
                
            } catch (error) {
                console.error('加载视频列表失败:', error);
                Object.values(videoGrids).forEach(grid => {
                    grid.innerHTML = `<div class="error">加载失败: ${error.message}</div>`;
                });
            }
        }
        
        // 创建视频卡片
        function createVideoCard(videoFile, metadata) {
            const card = document.createElement('div');
            card.className = 'video-card';
            card.setAttribute('data-video', videoFile);
            
            card.innerHTML = `
                <div class="video-thumbnail"></div>
                <div class="video-card-content">
                    <h3 class="video-card-title">${metadata.title}</h3>
                    <div class="video-card-meta">
                        <span>播放量: ${metadata.views}</span>
                        <span>${metadata.duration}</span>
                    </div>
                </div>
            `;
            
            // 添加点击事件
            card.addEventListener('click', () => {
                playVideo(videoFile, metadata);
            });
            
            return card;
        }
        
        // 播放视频函数
        function playVideo(videoFile, metadata) {
            const data = metadata || videoMetadata[videoFile] || {
                title: videoFile,
                views: '0',
                duration: '未知',
                uploadTime: '未知',
                description: '暂无描述'
            };
            
            playerContainer.classList.add('active');
            videoTitle.textContent = data.title;
            videoMeta.innerHTML = `
                <span>播放量: ${data.views}</span>
                <span>时长: ${data.duration}</span>
                <span>上传时间: ${data.uploadTime}</span>
            `;
            videoDescription.textContent = data.description;
            
            // 设置视频源 - 使用服务器路径
            const videoPath = `/videos/${encodeURIComponent(videoFile)}`;
            videoSource.src = videoPath;
            videoElement.load();
            
            // 尝试播放视频（注意：自动播放可能被浏览器阻止）
            const playPromise = videoElement.play();
            if (playPromise !== undefined) {
                playPromise.catch(error => {
                    console.log('自动播放失败，可能需要用户交互', error);
                });
            }
            
            // 滚动到播放器
            playerContainer.scrollIntoView({ behavior: 'smooth' });
        }
        
        // 导航切换
        navItems.forEach(item => {
            item.addEventListener('click', function() {
                // 更新活跃状态
                navItems.forEach(nav => nav.classList.remove('active'));
                this.classList.add('active');
                
                const category = this.getAttribute('data-category');
                
                // 显示/隐藏区域
                if (category === 'all') {
                    Object.values(sections).forEach(section => {
                        section.style.display = 'block';
                    });
                } else {
                    Object.keys(sections).forEach(key => {
                        sections[key].style.display = key === category ? 'block' : 'none';
                    });
                }
            });
        });
        
        // 搜索功能
        searchBtn.addEventListener('click', performSearch);
        searchInput.addEventListener('keypress', function(e) {
            if (e.key === 'Enter') performSearch();
        });
        
        function performSearch() {
            const query = searchInput.value.trim().toLowerCase();
            if (!query) return;
            
            // 在实际应用中，这里会有更复杂的搜索逻辑
            alert(`搜索: ${query}\n在实际应用中，这里会显示搜索结果`);
        }
        
        // 初始化：加载视频列表
        document.addEventListener('DOMContentLoaded', () => {
            loadVideoList();
        });
    </script>
</body>
</html>